package com.xc.round1Assessment;

/**
 * @author 谢忱
 * @version 1.0
 */
public class Student {
    private String id;
    private String name;
    private double grade;
    private boolean isOff;

    public Student(String id, String name, double grade) {
        this.id = id;
        this.name = name;
        this.grade = grade;
    }

    public static boolean update(Student student, double grade) {
        if(student.isOff) {
            System.out.println("The student has withdrawn from school");
            return false;
        }
        int score = (int)Math.round(grade);
        if (score < 0 || score > 100) {
            System.out.println("The score is illegal");
            return false;
        }
        student.grade = score;
        System.out.println("modify successfully");
        return true;
    }

    public static void unpassedList(Student[] students) {
        System.out.print("Students who fail an exam : ");
        for (Student student : students) {
            if (student.isPassed()) {
                System.out.println(student.toString());
            }
        }

        System.out.println();

        System.out.print("Students who dropped out : ");
        for (Student student : students) {
            if (student.isOff) {
                System.out.println(student.toString());            }
        }
    }

    public boolean isPassed() {
        return grade > 60;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", grade=" + grade +
                ", isOff=" + isOff +
                '}';
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getGrade() {
        return grade;
    }

    public void setGrade(double grade) {
        this.grade = grade;
    }

    public boolean isOff() {
        return isOff;
    }

    public void setOff(boolean off) {
        isOff = off;
    }
}
